home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Better Apple Event Coding / Code Samples / List.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  2.1 KB  |  105 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------------------
  2.  
  3.     Program:    CPlusTESample 2.0AE
  4.     File:        List.h
  5.  
  6.     by Andrew Shebanow
  7.     of Apple Macintosh Developer Technical Support
  8.     with modifications by Eric Berdahl
  9.  
  10.     Copyright © 1989-1990 Apple Computer, Inc.
  11.     Copyright © 1992 Eric Berdahl
  12.     All rights reserved.
  13.  
  14. ------------------------------------------------------------------------------------------*/
  15.  
  16. #ifndef __LIST__
  17. #define __LIST__
  18.  
  19. typedef    void    Object;
  20.  
  21. // ObjectHandle is an Handle full of object pointers,
  22. // which we use as an array
  23. // We do two typedefs here to make that a
  24. // bit easier to read, since:
  25. //        typedef void*** ObjectHandle;
  26. // is just too wierd.
  27. typedef Object* ObjectRef;
  28. typedef ObjectRef** ObjectHandle;
  29.  
  30. class TList {
  31. public:
  32.     TList();
  33.  
  34.     virtual void            InsertFirst(Object* obj);
  35.     virtual void            InsertLast(Object* obj);
  36.  
  37.     virtual void            MoveToFront(Object* obj);
  38.     virtual void            MoveToBack(Object* obj);
  39.     virtual void            MoveFront(Object* obj);
  40.     virtual void            MoveBack(Object* obj);
  41.  
  42.     virtual void            Remove(Object* obj);
  43.     virtual void            RemoveAll();
  44.     virtual void            Delete(Object* obj);
  45.     virtual void            DeleteAll();
  46.  
  47.     virtual short            Count() const;
  48.  
  49. protected:
  50.     virtual Object*            At(short idx) const;
  51.     virtual short            FindIdx(Object* obj);
  52.  
  53.     short                    fNumObjs;        // the number of elements in the list
  54.  
  55. private:
  56.     friend class TListIterator;
  57.  
  58.     ObjectHandle    fObjects;
  59. };
  60.  
  61. // Our inline methods - we do these so often, and they are so small,
  62. // that we make them inlines
  63.  
  64. inline short TList::Count() const
  65. {
  66.     return fNumObjs;
  67. }
  68.  
  69. class TListIterator {
  70. public:
  71.                     TListIterator(const TList* ls);
  72.     virtual    Object*    Next();
  73.     virtual    Object*    Prev();
  74.     virtual    Object*    First();
  75.     virtual    Object*    Last();
  76.  
  77. private:
  78.     const TList*    fList;
  79.     short            fIdx;
  80. };
  81.  
  82. inline Object* TListIterator::Next()
  83. {
  84.     return fList->At(++fIdx);
  85. }
  86.  
  87. inline Object* TListIterator::Prev()
  88. {
  89.     return fList->At(--fIdx);
  90. }
  91.  
  92. inline Object* TListIterator::First()
  93. {
  94.     fIdx = 0;
  95.     return fList->At(fIdx);
  96. }
  97.  
  98. inline Object* TListIterator::Last()
  99. {
  100.     fIdx = fList->Count() - 1;
  101.     return fList->At(fIdx);
  102. }
  103.  
  104. #endif
  105.